/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.io.Serializable;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import models.TravelWayDTO;
import models.TripDTO;
import models.cittaDTO;
import models.hotelDTO;
import models.stanzaDTO;
import models.tourDTO;

/**
 *
 * @author simone
 */
public class ComboBoxCellRender extends JLabel implements ListCellRenderer, Serializable {

    private static final Color HIGHLIGHT_COLOR = new Color(205, 205, 218);

    public ComboBoxCellRender() {
        setOpaque(true);
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) 
    {
        if (value == null)
            return null;
        switch (value.getClass().toString()) {
            case "class models.TripDTO":
                TripDTO tDTO = (TripDTO) value;
                setText(tDTO.getInfo());
                break;
            case "class models.tourDTO":
                tourDTO trDTO = (tourDTO) value;
                setText(trDTO.getNameTour());
                break;
            case "class models.hotelDTO":
                hotelDTO hDTO = (hotelDTO) value;
                setText(hDTO.getInfo());
                break;
            case "class models.stanzaDTO":
                stanzaDTO sDTO = (stanzaDTO) value;
                setText(sDTO.getStanzaName());
                break;
            case "class models.cittaDTO":
                cittaDTO cDTO = (cittaDTO) value;
                setText(cDTO.getCityName()+" -- "+cDTO.getCountryName());
                break;
            case "class models.TravelWayDTO":
                TravelWayDTO twDTO = (TravelWayDTO) value;
                setText(twDTO.getNameWay());
                break;
            default:
                setText("No city selected");
                break;
        }

        setFont(new Font("Serif", Font.PLAIN, 14));
        if (isSelected) {
            setBackground(HIGHLIGHT_COLOR);
            //setForeground(Color.LIGHT_GRAY);
        } else {
            setBackground(Color.WHITE);
            //setForeground(Color.YELLOW);
        }
        return this;
    }

}
